from selenium.webdriver.support.select import Select
from public.tools import reGetString
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time

testCase = "DBshop006-删除取消的订单的流程"
#1. 进入后台销售管理订单管理,记录目前总订单数
firefox=openBrowser(url)
firefox.get(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,'销售管理','订单管理')
s=firefox.find_element_by_xpath("//body").text
l="\(订单数：" #left 左边界
r="\)"        #right 右边界
num1=int(reGetString(s,l,r))
# 2.删选已取消的订单，记录删除订单后的订单总数
s=Select(firefox.find_element_by_id('order_state'))
s.select_by_visible_text('已取消')
firefox.find_element_by_xpath('//button').click()
firefox.find_element_by_link_text('编辑查看').click()
firefox.find_element_by_link_text('删除订单').click()
firefox.switch_to.alert.accept()
time.sleep(3)
s1=firefox.find_element_by_xpath("//body").text
l="\(订单数："  # left 左边界
r="\)"  # right 右边界
num2=int(reGetString(s1, l, r))
# 断言：订单数是否比删除之前要少1
if num1-num2==1:
    writeLog("%s 测试通过"%testCase)
else:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()